package com.hc.homestay.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hc.homestay.commons.ResultMap;
import com.hc.homestay.mapper.ToGuestHomeMapper;
import com.hc.homestay.pojo.ToGuestHome;
import com.hc.homestay.service.ToGuestHomeService;

@Service
public class ToGuestHomeServiceImpl implements ToGuestHomeService {

	@Autowired
	private ToGuestHomeMapper ToGuestHomeMapper;

	@Override
	public ToGuestHome selectByPrimaryKey(Integer id) {
		return ToGuestHomeMapper.selectByPrimaryKey(id);
	}

	@Override
	public ResultMap<ToGuestHome> selectByPage(Map<String, Object> paramMap) {

		Integer pageIndex = 1;
		Integer pageSize = 5;
		if (paramMap.get("page") != null && !paramMap.get("page").equals("")) {
			pageIndex = (Integer) paramMap.get("page");
		}

		if (paramMap.get("limit") != null && !paramMap.get("limit").equals("")) {
			pageSize = (Integer) paramMap.get("limit");
		}

		Page<ToGuestHome> page = new Page<ToGuestHome>(pageIndex, pageSize);

		QueryWrapper<ToGuestHome> queryWrapper = new QueryWrapper<>();

		if (paramMap != null && (Integer) paramMap.get("ghId") != null && (Integer) paramMap.get("ghId") > 0) {
			queryWrapper.like("gh_id", (Integer) paramMap.get("ghId"));
		}

		IPage<ToGuestHome> mapIPage = ToGuestHomeMapper.selectPage(page, queryWrapper);
		List<ToGuestHome> records = mapIPage.getRecords();

		return new ResultMap<ToGuestHome>(records, (int) mapIPage.getTotal());
	}
}
